package laps.dataaccess.mysql;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import laps.dataaccess.AdministratorDAO;
import laps.dataaccess.CompensatableDaysDAO;
import laps.dataaccess.CompensationClaimDAO;
import laps.dataaccess.DAOFactory;
import laps.dataaccess.EmployeeDAO;
import laps.dataaccess.LeaveRecordDAO;
import laps.dataaccess.PublicHolidayDAO;
import laps.dataaccess.RankLeaveDAO;

public class DAOFactoryImpl extends DAOFactory {
	private final String CONSTR = "jdbc:mysql//localhost:3306/laps_db";
	private final String USR = "javauser";
	private final String PWD = "password";
	private Connection connection;

	public DAOFactoryImpl() {
		try {
			Class.forName("com.mysql.jdbc.Driver");
			connection = DriverManager.getConnection(CONSTR, USR, PWD);

		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
	
	public void closeConnection() {
		try {
			connection.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	@Override
	public EmployeeDAO getEmployeeDAO() {
		return new EmployeeDAOImpl(connection);
	}

	@Override
	public PublicHolidayDAO getPublicHolidayDAO() {
		return new PublicHolidayDAOImpl(connection);
	}

	@Override
	public LeaveRecordDAO getLeaveRecordDAO() {
		return new LeaveRecordDAOImpl(connection);
	}

	@Override
	public RankLeaveDAO getRankLeaveDAO() {

		return new RankLeaveDAOImpl(connection);
	}

	@Override
	public CompensationClaimDAO getCompensationClaimDAO() {

		return new CompensationClaimDAOImpl(connection);
	}

	@Override
	public CompensatableDaysDAO getCompensatableDaysDAO() {
		// TODO Auto-generated method stub
		return new CompensatableDaysDAOImpl(connection);
	}

	@Override
	public AdministratorDAO getAdministratorDAO() {

		return new AdministratorDAOImpl(connection);
	}

}
